<?php
/**
 * | ---------------------------------------------------------------------------------------------------
 * | Author：johnxu <fsyzxz@163.com>.
 * | ---------------------------------------------------------------------------------------------------
 * | Home: https://www.johnxu.net.
 * | ---------------------------------------------------------------------------------------------------
 * | Data: 2018/12/31
 * | ---------------------------------------------------------------------------------------------------
 * | Desc: Table表
 * | ---------------------------------------------------------------------------------------------------
 * | Document: https://wiki.swoole.com/wiki/page/p-table.html
 * | ---------------------------------------------------------------------------------------------------
 */

$table = new \Swoole\Table( 1024 );
$table->column( 'id', \Swoole\Table::TYPE_INT, 4 );
$table->column( 'name', \Swoole\Table::TYPE_STRING, 32 );
$table->column( 'age', \Swoole\Table::TYPE_INT, 2 );
$table->create();

// 设置值：方式1
$table->set( 'imooc', array(
    'id'   => 1,
    'name' => 'peter',
    'age'  => 33
) );

// 设置值：方式2
$table['imooc1'] = array(
    'id'   => 2,
    'name' => 'tom',
    'age'  => 23
);

// 原子自增操作
$table->incr( 'imooc', 'age', 1 );

// 原子自减操作
$table->del( 'imooc' );

// 获取值：方式1
print_r( $table->get( 'imooc' ) );

// 获取值：方式2
print_r( $table['imooc2'] );
